#!/bin/bash


# 判断是否为空置
if [ -n "$1" ] ; then
  data_date=$1
else
  data_date=`date -d '-1 days' +%F`
fi


# 加载数据到表中
ADS_LOG_LOAD_ODS_SQL="
LOAD DATA INPATH '/warehouse/ads_log/${data_date}'
    OVERWRITE INTO TABLE jtp_ads_warehouse.ods_ads_log_inc PARTITION (dt = '${data_date}');
"

# 1. 广告信息表
ODS_ADS_INFO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/ads/${data_date}' OVERWRITE INTO TABLE
    jtp_ads_warehouse.ods_ads_info_full PARTITION (dt = '${data_date}') ;
"

# 2. 广告平台映射表
ODS_ADS_PLATFORM_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/ads_platform/${data_date}' OVERWRITE INTO TABLE
    jtp_ads_warehouse.ods_ads_platform_full PARTITION (dt = '${data_date}') ;
"

#  3. 广告平台信息表
ODS_PLATFORM_INFO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/platform_info/${data_date}' OVERWRITE INTO TABLE
    jtp_ads_warehouse.ods_platform_info_full PARTITION (dt = '${data_date}') ;
"


#  4. 产品信息表
ODS_PRODUCT_INFO_FULL_SQL="
LOAD DATA INPATH '/warehouse/ads_basic/product/${data_date}' OVERWRITE INTO TABLE
    jtp_ads_warehouse.ods_product_info_full PARTITION (dt = '${data_date}') ;
"


/opt/module/spark/bin/beeline -u jdbc:hive2://node101:10001 -n bwie -e "${ADS_LOG_LOAD_ODS_SQL}${ODS_ADS_INFO_FULL_SQL}${ODS_ADS_PLATFORM_FULL_SQL}${ODS_PLATFORM_INFO_FULL_SQL}${ODS_PRODUCT_INFO_FULL_SQL}"


